import json
import pandas as pd

# 1.从josn文件中读取数据，并保存在josn_data变量中
json_data = open('active_apis_data.txt', encoding='utf-8').read()
# print(type(json_data)) #str
# 2.json调用loads()方法将字符串数据转换成列表
data = json.loads(json_data)
#print(type(data)) #list
dictArr = []
for item in data:
    #print(type(item))  -->dict
    dict = {}
    if item is None:
        continue;
    if 'tags' in item:
        tags = item['tags']
        tagStr = ''
        count = 0
        for tag in tags:
            tagStr += tag + '.'
            count += 1
            if count == 3:
                break;
        tagStr = tagStr[:-1]
        dict['tags'] = tagStr

    if 'description' in item:
        dict['des'] = item['description']

    dictArr.append(dict)

pd.DataFrame(dictArr).to_csv('active_apis_tags_des.csv',index=False)

